package gui;


import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.KeyStroke;

import settings.guiSettings;

public class MenuBar extends JMenuBar{
	private static final long serialVersionUID = -6023043426639521021L;
	private JMenu _mainMenu = new JMenu("Spiel");
	
	public MenuBar() {
		make_mainMenu();
	}

	private void make_mainMenu() {
		_mainMenu.add(new NewGameAction());
		_mainMenu.add(new JSeparator());
		_mainMenu.add(new CloseGame());
		super.add(_mainMenu);	
	}
	
	class NewGameAction extends AbstractAction{
		private static final long serialVersionUID = 1401339992798471780L;
		public NewGameAction() {
			super("Neues Spiel");
			putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control N"));
			putValue(SHORT_DESCRIPTION, "Neues Spiel starten");	
		}
		public void actionPerformed(ActionEvent arg0) {
			GuiController.getInstance().getMap().clearMap();
		}
    }
	class CloseGame extends AbstractAction{
		private static final long serialVersionUID = 1401339992798471780L;
		private Component outerComp;
		public CloseGame() {
			super("Beenden");
			putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Q"));
			putValue(SHORT_DESCRIPTION, "Spiel beenden");	
		}
		public void actionPerformed(ActionEvent arg0) {
			if (guiSettings.CLOSEWHTHPROMT) {
				int pane = JOptionPane.showConfirmDialog(outerComp,"Wollen Sie das Spiel wirklich beenden?", "Spiel beenden", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
				if (pane == 0) {
					System.exit(0);			
				}				
			} else System.exit(0);

		}
    }
}
